<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            list-style: none;
        }
        .box {
          width: 50%;
          height: 180px;
          margin: 200px auto;
          position: relative;
        }
        .img_list {
          width: 100%;
          height: 150px;
        }
        .img_list li {
          float: left;
          position: absolute;
          left: 0;
          border-radius: 10px;
          transition: all 0.5s;
        }
        .img_list li img {
          width: 400px;
          height: 260px;
          border-radius: 10px;
        }
        #last1 {
          left: 0;
          z-index: 1;
        }
        #last2 {
          left: 290px;
          transform: scale(1.25);
          z-index: 99;
        }
        #last3 {
          left: 645px;
          z-index: 1;
        }
        #but {
          position: absolute;
          z-index: 999;
          bottom: 200px;
        }
        .span {
          width: auto;
          height: 20px;
          position: absolute;
          bottom: -136px;
          z-index: 99;
          left: 66%;
          transform: translateX(-50%);
          background-color: pink;
          line-height: 13px;
          border-radius: 20px;
        }
        .span span {
          width: 30px;
          height: 5px;
          text-align: center;
          display: inline-block;
          background-color: #e6e6e6;
          margin-left: 20px;
          border-radius: 3px;
        }
        .span span:nth-child(1) {
          margin-left: 0px;
          background-color: #ec4141;
        }
    </style>
</head>
<body>
    <div class="box" id="app">
        <ul class="img_list" @mouseover="handler" @mouseleave="leave()">
          <li
            v-for="(val, index) in banners"
            :key="Math.random()"
            :id="'last' + (index + 1)"
          >
            <img class="img" :src="val.imageUrl" @click="handlerCli(index-1)" alt=""/>
          </li>
     
          <div class="span">
            <span
              v-for="(val, index) in banners"
              :key="Math.random()"
              @mouseover="mouse(index)"
              @mouseleave="leave()"
            ></span>
          </div>
        </ul>
      </div>
</body>
</html>
 <script src="./vue.js"></script>
<script>
let li = [];
let time;
let index = 0;
new Vue({
    el: '#app',
    data() {
        return {
            elenent: [],
            banners: [],
            li1: []
        }
    },
    mounted() {
    this.initImg();
    },
    beforeDestroy() {
        clearInterval(time);
    },
    methods: {
    handler(){
        clearInterval(time);
    },
    handlerCli(e){
    if(e<0){
      e = 3
    }
    let libox = document.getElementsByClassName("img_list")[0].children;
    clearInterval(time);
    li = JSON.parse(JSON.stringify(this.li1[e]));
    if (e > index) {
      index = e;
      for (let i = 0; i < li.length; i++) {
        libox[i].id = li[i];
      }
      this.right();
      num = e;
    }

    if (e < index) {
      index = e;
      for (let i = 0; i < li.length; i++) {
        libox[i].id = li[i];
      }
      this.left();
      num = e;
    }
    },
    //初始化图片
    initImg() {
      new Promise((resolve, reject) => {
        //请求图片
          //console.log(res.banners, "1234img");
          this.banners = [
          {imageUrl: 'https://pic3.zhimg.com/v2-6b1c15d2d8e20544229d392f5b86011e_r.jpg'},
          {imageUrl: 'https://pic4.zhimg.com/v2-bdc4d2dec43cb192033122dce5da4c27_r.jpg'},
          {imageUrl: 'https://pic3.zhimg.com/v2-dab7c36f6b2b3129f49ce90b636217a2_r.jpg'},
          {imageUrl: 'https://pic1.zhimg.com/v2-1efd50c5d9626ddaecd36e0d05e10e20_r.jpg'}
        ];
          //给定义数组赋值
 
          for (var i = 0; i < this.banners.length; i++) {
            li[i] = "last" + (i + 1);
          }
          // for (var i = 0; i < this.banners.length; i++) {
          //   this.li1[i] = li
          //   li.unshift(li.pop());
          // }
 
          let arr = [];
 
          for (let i = 0; i < this.banners.length; i++) {
            this.li1.push(JSON.parse(JSON.stringify(li)));
            li.unshift(li.pop());
          }
          //console.log(this.li1, "zxc123");
          resolve();
      }).then(() => {
        //开启图片轮播
        //console.log(li,456)
        //this.li1 = JSON.parse(JSON.stringify(arr))
        console.log(this.li1, "zxc");
        time = setInterval(this.right1, 2500);
      });
    },
    right1() {
      let libox = document.getElementsByClassName("img_list")[0].children;
      let span = document.getElementsByClassName("span")[0].children;
      //删除最后一张图片放到第一张
      //console.log(li,456)
      li.unshift(li.pop());
      for (let i = 0; i < span.length; i++) {
        span[i].style.background = "#e6e6e6";
      }
      index++;
      if (index > span.length - 1) {
        index = 0;
 
      }
      span[index].style.background = "#ec4141";
 
      for (let i = 0; i < li.length; i++) {
        libox[i].id = li[i];
      }
    },
    right() {
      let libox = document.getElementsByClassName("img_list")[0].children;
      let span = document.getElementsByClassName("span")[0].children;
      //删除最后一张图片放到第一张
      //li.unshift(li.pop());
      //console.log(li);
      //console.log(index,'zxc')
      for (let i = 0; i < span.length; i++) {
        span[i].style.background = "#e6e6e6";
      }
      if (index > span.length - 1) {
        index = 0;
      }
      span[index].style.background = "#ec4141";
      //index++;
      for (let i = 0; i < li.length; i++) {
        libox[i].id = li[i];
      }
    },
    left() {
      let libox = document.getElementsByClassName("img_list")[0].children;
      let span = document.getElementsByClassName("span")[0].children;
      //删除最后一张图片放到第一张
      //li.push(li.shift());
      //console.log(li);
      //console.log(index,'zxc')
      for (let i = 0; i < span.length; i++) {
        span[i].style.background = "#e6e6e6";
      }
      if (index < 0) {
        index = 0;
      }
      span[index].style.background = "#ec4141";
      //index--
    },
    mouse(e) {
      let libox = document.getElementsByClassName("img_list")[0].children;
      clearInterval(time);
      li = JSON.parse(JSON.stringify(this.li1[e]));
      //console.log(li,789)
      if (e > index) {
        index = e;
        for (let i = 0; i < li.length; i++) {
          libox[i].id = li[i];
        }
        this.right();
        num = e;
      }
 
      if (e < index) {
        index = e;
        for (let i = 0; i < li.length; i++) {
          libox[i].id = li[i];
        }
        this.left();
        num = e;
      }
    },
    leave() {
      clearInterval(time);
      //index = num
      time = setInterval(this.right1, 2500);
    },
  },
})
</script>